/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.frm.bpm.entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;

/**
 *
 * @author Yuwei
 */
@Entity
public class SupplierPaymentRecord implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String supplierPaymentRecordId; 
    private Timestamp supplierPaymentDate;
    private String supplierPaymentDateStr;
    private String paymentMethod;
    private double paymentAmount;
    private String paymentReference;
    
    @OneToOne(targetEntity = SupplierInvoice.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER, mappedBy="supplierPaymentRecord")
    private SupplierInvoice supplierInvoice;
    @OneToOne(targetEntity = SupplierReceipt.class, cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.EAGER)
    private SupplierReceipt supplierReceipt;
    
    private static final SimpleDateFormat formatter = new SimpleDateFormat("MMMMM dd, yyyy");
    
    public SupplierPaymentRecord(){
        supplierPaymentRecordId = "";
        supplierPaymentDate = new Timestamp(new Date().getTime());
        supplierPaymentDateStr = convertToDateFormat(supplierPaymentDate);
        paymentMethod = "";
        paymentAmount = (double)0;
    }
    private String convertToDateFormat(Timestamp timeStamp){
        return formatter.format((java.util.Date) timeStamp);
    }
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getSupplierPaymentRecordId() {
        return supplierPaymentRecordId;
    }

    public void setSupplierPaymentRecordId(String supplierPaymentRecordId) {
        this.supplierPaymentRecordId = supplierPaymentRecordId;
    }



    public double getPaymentAmount() {
        return paymentAmount;
    }

    public void setPaymentAmount(double paymentAmount) {
        this.paymentAmount = paymentAmount;
    }

    public String getPaymentMethod() {
        return paymentMethod;
    }

    public void setPaymentMethod(String paymentMethod) {
        this.paymentMethod = paymentMethod;
    }

    public SupplierInvoice getSupplierInvoice() {
        return supplierInvoice;
    }

    public void setSupplierInvoice(SupplierInvoice supplierInvoice) {
        this.supplierInvoice = supplierInvoice;
    }

    public Timestamp getSupplierPaymentDate() {
        return supplierPaymentDate;
    }

    public void setSupplierPaymentDate(Timestamp supplierPaymentDate) {
        this.supplierPaymentDate = supplierPaymentDate;
    }

    public String getSupplierPaymentDateStr() {
        return supplierPaymentDateStr;
    }

    public void setSupplierPaymentDateStr(String supplierPaymentDateStr) {
        this.supplierPaymentDateStr = supplierPaymentDateStr;
    }

    public SupplierReceipt getSupplierReceipt() {
        return supplierReceipt;
    }

    public void setSupplierReceipt(SupplierReceipt supplierReceipt) {
        this.supplierReceipt = supplierReceipt;
    }

    public String getPaymentReference() {
        return paymentReference;
    }

    public void setPaymentReference(String paymentReference) {
        this.paymentReference = paymentReference;
    }
    
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof SupplierPaymentRecord)) {
            return false;
        }
        SupplierPaymentRecord other = (SupplierPaymentRecord) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "merlion.frm.bpm.entity.SupplierPaymentRecord[ id=" + id + " ]";
    }
    
}
